package com.mkono.infra.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.mkono.infra.R;
import com.mkono.infra.untils.CIRdeal;

/**
 * Created by huang on 2019/11/2.
 */

public class MainFragment extends Fragment implements View.OnClickListener {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //布局文件转成View
        //参数1：Fragment需要加载的布局文件
        //参数2：加载layout的父ViewGroup
        //参数1：是否返回父ViewGroup对象，false为不
        View view = inflater.inflate(R.layout.activity_main ,container,false);
        Button on = view.findViewById(R.id.on);
        on.setOnClickListener(this);

        Button off = view.findViewById(R.id.off);
        off.setOnClickListener(this);

        Button task = view.findViewById(R.id.task);
        task.setOnClickListener(this);

        Button open = view.findViewById(R.id.open);
        open.setOnClickListener(this);

        Button tiaogao = view.findViewById(R.id.tiaogao);
        tiaogao.setOnClickListener(this);

        Button tiaodi = view.findViewById(R.id.tiaodi);
        tiaodi.setOnClickListener(this);
        return view;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.on:
                //62的2进制01100010
                int [] dengon = {9000,4500,//开始
                    560,560,560,1680,560,1680, 560,560,
                    560,560,560,560,560,1680, 560,560,
                    560,560,560,1680,560,1680, 560,560,
                    560,560,560,560,560,1680, 560,560,
                    560,560,560,1680,560,1680, 560,560,
                    560,560,560,560,560,1680, 560,560,
                    560,560,560,1680,560,1680, 560,560,
                    560,560,560,560,560,1680, 560,560,
//                        560,560, 560,1680, 560,560,560,560,560,560,560,1680,560,1680,
                    560,20000};//结束
                CIRdeal.transmitKey(getActivity(), dengon);
                break;
            case R.id.off:
                //18的2进制00011000
                int [] dengoff = {9000,4500,//开始
                        560,560,560,560,560,560,560,1680,
                        560,1680,560,560,560,560,560,560,
                        560,560,560,560,560,560,560,1680,
                        560,1680,560,560,560,560,560,560,
                        560,560,560,560,560,560,560,1680,
                        560,1680,560,560,560,560,560,560,
                        560,560,560,560,560,560,560,1680,
                        560,1680,560,560,560,560,560,560,
                        560,20000};//结束
                CIRdeal.transmitKey(getActivity(), dengoff);
                break;
            case R.id.task:
                //30的2进制00110000
                int [] dengtask = {9000,4500,//开始
                        560,560,560,560,560,1680,560,1680,
                        560,560,560,560,560,560,560,560,
                        560,560,560,560,560,1680,560,1680,
                        560,560,560,560,560,560,560,560,
                        560,560,560,560,560,1680,560,1680,
                        560,560,560,560,560,560,560,560,
                        560,560,560,560,560,1680,560,1680,
                        560,560,560,560,560,560,560,560,
                        560,20000};//结束
                CIRdeal.transmitKey(getActivity(), dengtask);
                break;
            case R.id.open:
                //7a的2进制0111 1010
                int [] dengopen = {9000,4500,//开始
                        560,560,560,1680,560,1680,560,1680,
                        560,1680,560,560,560,1680, 560,560,
                        560,560,560,1680,560,1680,560,1680,
                        560,1680,560,560,560,1680, 560,560,
                        560,560,560,1680,560,1680,560,1680,
                        560,1680,560,560,560,1680, 560,560,
                        560,560,560,1680,560,1680,560,1680,
                        560,1680,560,560,560,1680, 560,560,
                        560,20000};//结束
                CIRdeal.transmitKey(getActivity(), dengopen);
                break;
            case R.id.tiaogao:
                //90的2进制10010000
                int [] gao = {9000,4500,//开始
                        //数据码
                        560,1680, 560,560, 560,560, 560,1680,
                        560,560, 560,560, 560,560, 560,560,
                        //数据码
                        560,1680, 560,560, 560,560, 560,1680,
                        560,560, 560,560, 560,560, 560,560,
                        //数据码
                        560,1680, 560,560, 560,560, 560,1680,
                        560,560, 560,560, 560,560, 560,560,
                        //数据码
                        560,1680, 560,560, 560,560, 560,1680,
                        560,560, 560,560, 560,560, 560,560,
//                        560,560, 560,1680, 560,560,560,560,560,560,560,1680,560,1680,
                        560,20000};//结束
                CIRdeal.transmitKey(getActivity(), gao);
                break;
            case R.id.tiaodi:
                //e0的2进制11100000
                int [] di = {9000,4500,//开始
                        //用户吗
                        560,1680,560,1680,560,1680,560,560,
                        560,560,560,560, 560,560,560,560,
                        560,1680,560,1680,560,1680,560,560,
                        560,560,560,560, 560,560,560,560,
                        560,1680,560,1680,560,1680,560,560,
                        560,560,560,560, 560,560,560,560,
                        560,1680,560,1680,560,1680,560,560,
                        560,560,560,560, 560,560,560,560,
//                        560,560, 560,1680, 560,560,560,560,560,560,560,1680,560,1680,
                        560,20000};//结束
                CIRdeal.transmitKey(getActivity(), di);
                break;
        }

    }
}
